package net.wanho.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.wanho.dto.OutStoreDTO;
import net.wanho.entity.OutStore;
import net.wanho.mapper.OutStoreMapper;
import net.wanho.service.OutStoreService;
import net.wanho.vo.OutStoreVo;
import net.wanho.vo.PageVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【out_store(出库单表)】的数据库操作Service实现
* @createDate 2025-05-05 02:08:26
*/
@Service
@RequiredArgsConstructor
public class OutStoreServiceImpl extends ServiceImpl<OutStoreMapper, OutStore> implements OutStoreService{
    private final OutStoreMapper outStoreMapper;

    @Override
    public PageVo<OutStoreVo> getPageList(OutStoreDTO outStoreDTO, Integer pageNum, Integer pageSize) {
        IPage<OutStore> page = new Page<>(pageNum, pageSize);
        List<OutStoreVo> outStoreVoList = outStoreMapper.selectOutStoreList(page, outStoreDTO);
        return new PageVo<>(
                page.getCurrent(),
                page.getSize(),
                page.getTotal(),
                page.getPages(),
                page.offset(),
                outStoreVoList
        );
    }

    @Override
    public void addOutStore(OutStoreDTO outStoreDTO) {
        OutStore outStore = new OutStore(
                outStoreDTO.getProductId(),
                outStoreDTO.getStoreId(),
                outStoreDTO.getUpdateBy(),
                outStoreDTO.getInPrice(),
                outStoreDTO.getOutNum(),
                "0"
        );

        save(outStore);
    }

    @Override
    public void updateOutStoreById(OutStoreDTO outStoreDTO) {
        OutStore outStore = new OutStore();
        outStore.setOutsId(outStoreDTO.getOutsId());
        outStore.setIsOut("1");

        updateById(outStore);
    }

}




